package com.globalLogic.geometry;

public class Segment {

	private Point start;
	private Point end;
	
	public Segment(double latitude, double longitude,double latitude2, double longitude2 ) {
		super();
		this.start = new Point(latitude,longitude);
		this.end = new Point(latitude2,longitude2);
	}
	public Point getStart() {
		return start;
	}
	public void setStart(Point start) {
		this.start = start;
	}
	public Point getEnd() {
		return end;
	}
	public void setEnd(Point end) {
		this.end = end;
	}

	public  double getLength() {  
        //
		double lat1 = start.getLatitude();
		double lng1 = start.getLongitude();
		
		double lat2 = end.getLatitude();
		double lng2 = end.getLongitude();
		
		
        double earthRadius = 6371;//kilometers  
        double dLat = Math.toRadians(lat2 - lat1);  
        double dLng = Math.toRadians(lng2 - lng1);  
        double sindLat = Math.sin(dLat / 2);  
        double sindLng = Math.sin(dLng / 2);  
        double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2)  
                * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2));  
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));  
        double dist = earthRadius * c;  
  
        return dist;  
    }
	@Override
	public String toString() {
		return "Segment [start=" + start + ", end=" + end + "]";
	}  

	
}
